package com.oauth.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.io.IOException;

@Controller
public class MainController {
	@GetMapping("/")
	public String index() {
		return "index";
	}
	@GetMapping("/main")
	public void mainTest(OAuth2AuthenticationToken token, HttpServletResponse response) throws IOException {
		System.out.println(token);
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().write("<h1>登录用户主页</h1>");
		response.getWriter().write(String.valueOf("欢迎你，GitHub用户："+token.getPrincipal().getAttributes().get("login")));
	}
}
